package bsc.war.mail;

import bsc.ejb.entity.Person;
import bsc.ejb.entity.ScoreCard;
import bsc.ejb.metadata.SMTP;
import javax.servlet.ServletContext;


/**
 *
 * @author Memo
 */
public class Relay {

    private Person person;
    private MailConsumer mailConsumer;
    private MailUtils.Type type;
    private MailSender mail_sender;
    private String mailContent;
    private boolean error;

    public Relay(Person person, ScoreCard scoreCard, MailUtils.Type type){
        this.person = person;
        this.type = type;
        this.error = false;
    }

    public void send(SMTP smtp, ServletContext context){
        try{
            mail_sender = MailSender.getInstance(smtp);
            mailConsumer = new MailConsumer();
            String subject = "";
            switch (type){
               case POINTER_DASHBOARD:{
                    subject = "subject";
                    mailContent = mailConsumer.getFileContent(context, MailUtils.pointerAlert);
               }
               case SCORECARD_DASHBOARD:{
                    subject = "subject";
                    mailContent = mailConsumer.getFileContent(context, MailUtils.scoreCardAlert);
               }
               case PROJECT_DASHBOARD:{
                    subject = "subject";
                    mailContent = mailConsumer.getFileContent(context, MailUtils.projectAlert);
               }
               case NOTIFICATION:{
                   
               }
               case PASSWORD_RECOVERY:{
                   
               }
            }
            mail_sender.send(MailUtils.REPLY_MAIL, subject, person.getEmail(), mailContent, mailConsumer.getType());
        }catch(Exception e){
            this.error=true;
        }
    }

    public boolean getError(){
        return error;
    }
}
